// server
package main

import (
	"github.com/kardianos/service"
	"github.com/miekg/dns"
)

type program struct{}

func (p *program) Start(s service.Service) error {
	// Start should not block. Do the actual work async.
	go p.run()
	return nil
}
func (p *program) run() {
	go func() {
		L("%s", "Start Udp server")
		var h = new(ServerHandler)
		srv := &dns.Server{Addr: settings.LocalHost, Net: "udp4", Handler: h}
		err := srv.ListenAndServe()
		if err != nil {
			L("Failed to set udp listener %s\n", err.Error())
		}
	}()
	go func() {
		L("%s", "Start TCP server")
		var h = new(ServerHandler)
		srv := &dns.Server{Addr: settings.LocalHost, Net: "tcp4", Handler: h}
		err := srv.ListenAndServe()
		if err != nil {
			L("Failed to set tcp listener %s\n", err.Error())
		}
	}()
}
func (p *program) Stop(s service.Service) error {
	// Stop should not block. Return with a few seconds.

	L("%s", "Stop DNS server")
	return nil
}
